package com.yswy.app.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yswy.app.dto.UserMoneyLogVo;
import com.yswy.app.service.UserMoneyLogService;
import com.yswy.domain.entity.UserMoneyLog;
import com.yswy.domain.mapper.UserMoneyLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;


@Slf4j
@Service
public class UserMoneyLogServiceImpl extends ServiceImpl<UserMoneyLogMapper, UserMoneyLog>
        implements UserMoneyLogService {


    @Override
    public Page<UserMoneyLog> listUserMoneyLog(Long userId, UserMoneyLogVo userMoneyLogVo) {
        Page<UserMoneyLog> resultPage = baseMapper.selectPage(new Page<>(userMoneyLogVo.getPageIndex(),
                        userMoneyLogVo.getPageSize())
                , Wrappers.<UserMoneyLog>lambdaQuery()
                                .eq(UserMoneyLog::getUserId , userId)
                                .eq(UserMoneyLog::getLogStatus ,userMoneyLogVo.getLogStatus() )
                        .orderByDesc(UserMoneyLog::getRecordTime));
        return resultPage;

    }

    @Override
    public void addUserMoneyLog(Long userId, Integer logType, Integer logStatus , Integer money ,String logMsg ) {
        save(UserMoneyLog.builder()
                .userId(userId)
                .logType(logType)
                .logStatus(logStatus)
                .logMsg(logMsg)
                .recordTime(new Date())
                .money(money)
                .build());
    }
}
